from question.serializers.label_serializers import *
from question.models import *
from rest_framework.viewsets import ReadOnlyModelViewSet
from rest_framework.generics import ListAPIView, GenericAPIView
from rest_framework.views import APIView
from rest_framework.response import Response
from user.models import *


class LabelView(ReadOnlyModelViewSet):
    queryset = Label.objects.all()
    serializer_class = LabelSerializer

    def get_serializer_class(self):
        if self.action == 'list':
            return LabelSerializer
        elif self.action == 'retrieve':
            return LabelDSerializer

        return self.serializer_class


class UserLabelsView(APIView):
    def get(self, request):
        user = User.objects.get(pk=request.user.id)
        data = user.labels
        serializer = LabelSerializer(instance=data, many=True)
        return Response(serializer.data)




